package edu.xidian.pnaWeb.web.service;

import edu.xidian.pnaWeb.petri.alg.EventCircleAlg;
import edu.xidian.pnaWeb.petri.alg.ReachableGraphAlg;
import edu.xidian.pnaWeb.petri.alg.SimphonAlg;
import edu.xidian.pnaWeb.petri.module.EventCircleInfo;
import edu.xidian.pnaWeb.petri.module.ReachGraphInfo;
import edu.xidian.pnaWeb.petri.module.SimphonInfo;
import edu.xidian.pnaWeb.web.model.AdminContext;
import edu.xidian.pnaWeb.web.service.api.AlgorithmService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description
 * @Author He
 * @Date 2021/10/23 15:47
 */
@Service
public class AlgorithmServiceImpl implements AlgorithmService {
	@Resource
	private ReachableGraphAlg reachableGraphAlg;
	@Resource
	private SimphonAlg simphonAlg;
	@Resource
	private EventCircleAlg eventCircleAlg;
	@Override
	public String generateReachGraph(Map params) {
		Integer step = (Integer) params.get("step");
		AdminContext adminContext = AdminContext.USER_INFO.get();
		ReachGraphInfo reachGraphInfo = reachableGraphAlg.generateReachGraphWithStep(adminContext.getPetriDO(), step);
		adminContext.setReachGraphInfo(reachGraphInfo);
		return reachGraphInfo.toString();
	}
	@Override
	public String generateSimphon(Map params){
		SimphonInfo simphonInfo = simphonAlg.generateSimphon();
		AdminContext adminContext = AdminContext.USER_INFO.get();
		adminContext.setSimphonInfo(simphonInfo);
		return simphonInfo.toString();
	}
	@Override
	public String generateEventWait(Map params){
		EventCircleInfo eventCircleInfo = eventCircleAlg.generateEventCircle();
		AdminContext adminContext = AdminContext.USER_INFO.get();
		adminContext.setEventCircleInfo(eventCircleInfo);
		return eventCircleInfo.toString();
	}
}
